<template>
  <el-dialog :visible.sync="value" :before-close="cancel">
    <template slot="title">
      {{id ? '编辑' : '新增'}}提现风控
    </template>
    <p style="color: #cccccc">1.当提现的⽤户达到以下配置的条件后，则此笔提现⾃动进⼊，异常提现界⾯，需要风控⼈员进⾏审核</p>
    <p style="color: #cccccc">2.每个层级⽬前只⽀持设置⼀条风控策略</p>
    <p style="color: #cccccc">3.这⾥的提现设置为层级提现风控设置，若这⾥没有设置到的层级都会按照“财务管理-提现管理-提现风控设置”的提现风控流程进⾏，若已经设置了层级的风控，则按照层级风控流程进
      ⾏</p>
    <el-form :inline="true"
             ref="strategyForm"
             :rules="strategyRule"
             label-width="150px"
             :disabled="loading"
             :model="form" class="demo-form-inline">
      <el-row>
        <el-col :span="8">
          <el-form-item label="用户层级　　" prop="level">
            <el-select v-model="form.levelId" placeholder="请选择用户层级">
              <el-option
                v-for="item in levelList"
                :label="item.name"
                :key="item.levelId"
                :value="item.levelId"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="8">
          <el-form-item label="单日提现金额" prop="dailyAmount">
            <el-input placeholder="请输入金额" v-model.number="form.dailyAmount">
              <template slot="prepend">></template>
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="单次提现金额" prop="amount">
            <el-input placeholder="请输入金额" v-model.number="form.amount">
              <template slot="prepend">></template>
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="当日提现次数" prop="dailyTimes">
            <el-input placeholder="请输入次数" v-model.number="form.dailyTimes">
              <template slot="prepend">></template>
              <template slot="append">次</template>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="首次提现金额" prop="firstAmount">
            <el-input placeholder="请输入金额" v-model.number="form.firstAmount">
              <template slot="prepend">></template>
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="当日盈利金额" prop="dailyProfit">
            <el-input placeholder="请输入金额" v-model.number="form.dailyProfit">
              <template slot="prepend">></template>
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="7日累计提现金额" prop="weeklyAmount">
            <el-input placeholder="请输入金额" v-model.number="form.weeklyAmount">
              <template slot="prepend">></template>
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="同IP多账号检测" prop="sameIpCheck">
            <el-radio-group v-model="form.sameIpCheck" size="medium">
              <el-radio-button :label="1" value="1">开启</el-radio-button>
              <el-radio-button :label="2" value="2">关闭</el-radio-button>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="同设备多账号检测" prop="sameDeviceCheck">
            <el-radio-group v-model="form.sameDeviceCheck" size="medium">
              <el-radio-button :label="1" value="1">开启</el-radio-button>
              <el-radio-button :label="2" value="2">关闭</el-radio-button>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">取 消</el-button>
      <el-button type="primary" @click="doSave({action: 'saveForm', form: 'strategyForm'})">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import {form, factory} from "@/build";
  import {
    addRiskStrategy,
    getStrategyDetail,
    updateRiskStrategy
  } from "@/services/api/strategy";
  import {getUserLevelList} from "@/services/api/userLevel";

  export default {
    name: "strategy-setting-dialog",
    props: ["value", "id", "rowData"],
    mixins: [form, factory],
    data() {
      return {
        levelList: [],
        form: {},
        strategyRule: {
          dailyAmount: factory.getRule("money"),
          amount: factory.getRule("money"),
          firstAmount: factory.getRule("money"),
          dailyProfit: factory.getRule("money"),
          weeklyAmount: factory.getRule("money"),
          levelId: [{required: true, message: "层级选择不能为空"}],
          dailyTimes: [
            {required: true, message: "单日提现次数不能为空"},
            {validator: factory.getValidator("nonNegativeInteger")}
          ],
          continuousMinutes: [
            {required: true, message: "连续提现时间配置不能为空"},
            {validator: factory.getValidator("nonNegativeInteger")}
          ],
          continuousWithdrawTimes: [
            {required: true, message: "连续提现次数不能为空"},
            {validator: factory.getValidator("nonNegativeInteger")}
          ],
          sameIpCheck: [
            {
              required: true,
              message: "同IP多账号检测为必选项",
              trigger: "change"
            }
          ],
          sameDeviceCheck: [
            {
              required: true,
              message: "同设备多账号检测为必选项",
              trigger: "change"
            }
          ]
        }
      };
    },
    methods: {
      cancel() {
        this.$emit("input", false);
      }
    },
    mounted() {
      this.bindGet(getUserLevelList, "levelList", {});
      if (this.id) {
        this.form = _.omit(this.rowData, ['createTime', 'lastUpdate']);
        this.bindSave(updateRiskStrategy, "saveForm", "form", {
          beforeSend: data => {
            return {...this.form, id: this.id}
          },
          afterSuccess: () => {
            this.resetForm("strategyForm");
            this.$parent.getAll();
            this.cancel();
          }
        });
      } else {
        this.bindSave(addRiskStrategy, "saveForm", "form", {
          afterSuccess: () => {
            this.resetForm("strategyForm");
            this.$parent.getAll();
            this.cancel();
          }
        });
      }
      this.getAll();
    }
  };
</script>

<style lang="scss" scoped>
</style>
